/*
 * nrand.h
 *
 *  Created on: Mar 29, 2015
 *      Author: silivas
 */

#ifndef SRC_NRAND_H_
#define SRC_NRAND_H_

#include <cstdlib>
using namespace std;
int nrand(int n){
	if(n<=0 || n > RAND_MAX){
		cout << "invalid n for nrand" << endl;
		return -1;
	}
	const int bucket_size = RAND_MAX / n;
	int r;
	do{
		r = rand() / RAND_MAX;
	}while(r>=n);
	return r;
}



#endif /* SRC_NRAND_H_ */
